<!DOCTYPE HTML>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <title> 卸载事件 </title>
  <script type="text/javascript">
    window.onunload = onunload_message();

    function onunload_message() {
      alert("您确定离开该网页吗？");
    }
  </script>
</head>

<body onunload="onunload_message()">
  欢迎学习JavaScript。
</body>

</html>